#include "frmtechcrst.h"
#include "ui_frmtechcrst.h"

FrmTechCrst::FrmTechCrst(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FrmTechCrst)
{
    ui->setupUi(this);
    this->initForm();
}

FrmTechCrst::~FrmTechCrst()
{
    delete ui;
}

void FrmTechCrst::initForm()
{
    ui->cbxSubjects->addItems(QStringList()<<"英语"<<"数学"<<"语文");
    ui->cbxSubjects->setCurrentIndex(1);

    int row=0,col=0;
    QStandardItemModel *model=new QStandardItemModel(3,3,this);
    model->setHorizontalHeaderLabels(QStringList()<<"教学班"<<"课程年级"<<"授课老师"<<"课时数"<<"预计学生数"<<"操作");
    model->setItem(row,col++,new QStandardItem("奥数1班"));
    model->setItem(row,col++,new QStandardItem("四年级"));
    model->setItem(row,col++,new QStandardItem("闫老师"));
    model->setItem(row,col++,new QStandardItem("15"));
    model->setItem(row,col++,new QStandardItem("5-6人"));

    row++;col=0;
    model->setItem(row,col++,new QStandardItem("奥数2班"));
    model->setItem(row,col++,new QStandardItem("五年级"));
    model->setItem(row,col++,new QStandardItem("闫老师"));
    model->setItem(row,col++,new QStandardItem("15"));
    model->setItem(row,col++,new QStandardItem("4-7人"));

    row++;col=0;
    model->setItem(row,col++,new QStandardItem("奥数3班"));
    model->setItem(row,col++,new QStandardItem("五年级"));
    model->setItem(row,col++,new QStandardItem("闫老师"));
    model->setItem(row,col++,new QStandardItem("15"));
    model->setItem(row,col++,new QStandardItem("5-7人"));

    ui->tableView->setModel(model);
    ui->tableView->setColumnWidth(0,120);
    ui->tableView->setColumnWidth(1,100);
    ui->tableView->setColumnWidth(2,100);
    ui->tableView->setColumnWidth(3,100);
    ui->tableView->horizontalHeader()->setStretchLastSection(true);

    for(int i=0;i<3;i++)
    {
        QPushButton *pushbtn1=new QPushButton;
        pushbtn1->setProperty("ID",i);
        pushbtn1->setText("选择学生");
        connect(pushbtn1,SIGNAL(clicked(bool)),this,SLOT(showCrstStu()));
        ui->tableView->setIndexWidget(model->index(i,5),pushbtn1);
    }
}

void FrmTechCrst::showCrstStu()
{
    FrmTechCrstStu *frm=new FrmTechCrstStu;
    frm->setWindowModality(Qt::WindowModal);
    frm->setWindowFlags(Qt::WindowCloseButtonHint);
    frm->setWindowTitle(tr("选择学生"));
    frm->show();
}
